<template>
  <div>
    <vault-days @submitFormDays="submitFormDays" :dataFrom="daysArray"/>
    <vault-time @submitFormTime="submitFormDays" :dataFromTime="timeArray"/>
    <vault-examine @submitFormExamine="submitFormDays" :dataFrom="examineArray"/>
    <vault-work :dataFrom="dataFrom" :range="range" @submitFormWork="submitFormWork"/>
  </div>
</template>
<script>
import {queryVaultConfig, queryWorkConfig, addWorkConfig} from '@/api/abnormal/config.js'
import VaultDays from './days'
import VaultTime from './time'
import VaultExamine from './examine'
import VaultWork from './work'
import {queryVaultConfigPut, vaultExinfo} from '@/api/abnormal/config.js'
export default {
  data() {
    return {
      daysArray: {},
      timeArray: {},
      dataFrom: {
        collectTime: ''
      },
      examineArray: {},
      range: [],
      configObject: {
        endTime: ''
      }
    }
  },
  created () {
    this.queryVaultConfig()
    this.queryWorkConfig()
  },
  methods: {
    // 开始统计
    async vaultExinfo () {
      const data = await vaultExinfo()
      if (data) {
        if (data.code === 200) {}
      }
    },
    submitFormWork (val) {
      this.addWorkConfig(val)
    },
    async addWorkConfig (val) {
      const data = await addWorkConfig(val)
      if (data) {
        if (data.code === 200) {
          this.queryWorkConfig()
        }
      }
    },
    // 查询非工作时间
    async queryWorkConfig () {
      const data = await queryWorkConfig()
      if (data) {
        if (data.code === 200) {
          this.range = data.data.range
          this.dataFrom.collectTime = data.data.collectTime
        } else {
          this.range = []
          this.dataFrom.collectTime = ''
        }
      }
    },
    // 查询
    async queryVaultConfig () {
      const data = await queryVaultConfig()
      if (data) {
        if (data.code === 200) {
         if (data.data.length > 1) {
           this.daysArray = data.data[0]
           this.daysArray.exceptionParamter = this.daysArray.exceptionParamter.split(',').map(item => {
             return {
               exceptionParamter: item
             }
           })
           this.timeArray = data.data[1]
           this.timeArray.exceptionParamter = this.timeArray.exceptionParamter.split(',').map(item => {
             return {
               exceptionParamter: item
             }
           })
           this.examineArray = data.data[2]
           this.examineArray.exceptionParamter = this.examineArray.exceptionParamter.split(',').map(item => {
             return {
               exceptionParamter: item
             }
           })
         }
        }
      }
    },
    async queryVaultConfigPut () {
      const data = await queryVaultConfigPut(this.configObject)
      if (data) {
        if (data.code === 200) {
          this.queryVaultConfig()
          if (this.configObject.type === 1) {
            this.vaultExinfo()
          }
        }
      }
    },
    submitFormDays (val) {
      this.configObject = val
      this.configObject.endTime = ''
      this.configObject.exceptionParamter = this.configObject.exceptionParamter.map(item => {
        return item.exceptionParamter
      })
      this.configObject.exceptionParamter = this.configObject.exceptionParamter.join(',')
      this.queryVaultConfigPut()
    },
  },
  components: {
    VaultDays,
    VaultTime,
    VaultWork,
    VaultExamine
  }
}
</script>
<style>
  .hljs{
    line-height: 1.8;
    font-family: Menlo,Monaco,Consolas,Courier,monospace;
    font-size: 12px;
    padding: 18px 24px;
    background-color: #fafafa;
    border: 1px solid #eaeefb;
    margin-bottom: 25px;
    border-radius: 4px;
    -webkit-font-smoothing: auto;
  }
  .system{
    font-size: 20px;
    text-align: left;
    line-height: 40px;
    margin-top: -10px;
    font-weight: bold;
  }
</style>
